package com.base.library.dialog;

import android.app.Dialog;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.base.library.R;


/**
 * @author 谢铖志 on 2017/10/13 13:48
 * @version V1.0
 * @modificationHistory
 * @modify by user: 谢铖志 on 2017/10/13 13:48
 */

public class BottomDialog extends Dialog {
    private ViewDataBinding contentViewBinding;
    private View contentView;

    public BottomDialog(@NonNull Context context, @LayoutRes int layout) {
        super(context, R.style.bottomDialog);
        contentViewBinding = DataBindingUtil.inflate(LayoutInflater.from(context), layout, null, false);
        contentView = contentViewBinding.getRoot();
        setContentView(contentView);
        ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();
        layoutParams.width = context.getResources().getDisplayMetrics().widthPixels;
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        contentView.setLayoutParams(layoutParams);
        getWindow().setGravity(Gravity.BOTTOM);
        setCanceledOnTouchOutside(true);
        getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
    }

    public <T extends ViewDataBinding> T getViewBinding() {
        return (T) contentViewBinding;
    }

    public View getContentView() {
        return contentView;
    }

}
